package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.Coach;
import com.example.fitnessservice.module.pojo.CourseDetails;
import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import com.example.fitnessservice.module.pojo.Result;
import com.example.fitnessservice.service.DirectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/director")
public class DirectorController {
    @Autowired
    private DirectorService directorService;

    //主管查询自己管理的教练，以及教练的课程
    @GetMapping("/{directorId}")
    public Result findCoach(@PathVariable Integer directorId){
        List<Coach> coaches = directorService.findCoach(directorId);

        Result result = new Result();
        if(coaches != null){
            result.setCode(200);
            result.setMsg("查询教练成功");
            result.setData(coaches);
        }else {
            result.setCode(500);
            result.setMsg("查询教练失败");
        }
        return result;
    }

    //根据教练的id，跟教练添加课程
    @PostMapping
    public Result addCourseByCoachId(@RequestBody CourseDetails courseDetails){
        System.out.println(courseDetails);
        boolean flag = directorService.addCourseByCoachId(courseDetails);

        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("成功添加课程");
        }else {
            result.setCode(500);
            result.setMsg("添加课程失败");
        }
        return result;
    }

    //根据课程的id，删除课程
    @DeleteMapping("/{courseId}")
    public Result deleteCourseByCourseId(@PathVariable Integer courseId){
        boolean flag = directorService.deleteCourseByCourseId(courseId);

        Result result = new Result();
        if (flag){
            result.setCode(200);
            result.setMsg("删除课程成功");
        }else {
            result.setCode(500);
            result.setMsg("删除课程失败");
        }
        return result;
    }

    /**
     * 修改课程的信息
     * @param courseDetails
     * @return
     */
    @PutMapping
    public Result updateCourse(@RequestBody CourseDetails courseDetails){
        boolean flag = directorService.updateCourse(courseDetails);

        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("课程信息修改成功");
        }else {
            result.setCode(500);
            result.setMsg("课程信息修改失败");
        }
        return result;

    }

    /**
     * 添加训练营课程信息
     *
     * @param courseDetailsCamp
     * @return
     */
    @PostMapping("/camp/{frequency}/{interval}")
    public Result addCamp(@RequestBody CourseDetailsCamp courseDetailsCamp, @PathVariable Integer frequency, @PathVariable Integer interval) {
        boolean flag = directorService.addCamp(courseDetailsCamp, frequency, interval);

        Result result = new Result();
        if (flag) {
            result.setCode(200);
            result.setMsg("添加训练营成功");
        } else {
            result.setCode(500);
            result.setMsg("添加训练营失败");
        }
        return result;
    }

    /**
     * 删除训练营信息
     * @param campId
     * @return
     */
    @DeleteMapping("/camp/{campId}")
    public Result deleteCamp(@PathVariable Integer campId){
        boolean flag = directorService.deleteCamp(campId);

        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("删除训练营成功");
        }else {
            result.setCode(500);
            result.setMsg("删除训练营失败");
        }
        return result;

    }

    /**
     * 修改训练营的信息
     * @param courseDetailsCamp
     * @return
     */
    @PutMapping("/camp")
    public Result updateCamp(@RequestBody CourseDetailsCamp courseDetailsCamp){
        boolean flag = directorService.updateCamp(courseDetailsCamp);

        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("修改训练营成功");
        }else {
            result.setCode(500);
            result.setMsg("修改训练营失败");
        }
        return result;
    }
}
